package cn.loan.service.impl;

import cn.loan.dao.QuotaMapper;
import cn.loan.entity.Quota;
import cn.loan.service.QuotaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: 毛苏宇
 * @Description: You can do it!
 * @Date: Create in 17:04 2019/3/21
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class QuotaServiceImpl implements QuotaService {

    @Autowired
    private QuotaMapper quotaMapper;


    @Override
    public boolean quotaIsExist(int userId) {
        return quotaMapper.findQuotaCountByUserId(userId) == 1 ? true : false;
    }

    @Override
    public boolean addQuota(Quota quota) {
        return quotaMapper.insertQuota(quota) == 1 ? true : false;
    }

    @Override
    public double getQuota(int userId) {
        return quotaMapper.findQuotaByUserId(userId);
    }

    @Override
    public double getBalance(int userId) {
        return quotaMapper.findBalanceByUserId(userId);
    }

    @Override
    public boolean modifyBalance(int userId, double balance) {
        return quotaMapper.updateBalance(userId, balance) == 1 ? true : false;
    }


}
